package com.zhujiekaifa.service.impl;

import com.zhujiekaifa.dao.UserDao;
import com.zhujiekaifa.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

//<bean id="userService-zj" class="com.zhujiekaifa.service.impl.UserServiceImpl">
//@Component("userService-zj")
@Service("userService-zj")
@Scope("prototype")
public class UserServiceImpl implements UserService {
    //<property name="userDao-zj" ref="userDao-zj"></property>
    //@Autowired//自动注入 按照数据类型从spring容器中进行匹配 会从spring容器其中找到UserDao这个类型的数据进行匹配
    //@Qualifier("userDao-zj")//按照ID的名称从容器中进行匹配 @Qualifier要结合@Autowired一起 //这两个注解相当于bean的注入
    @Resource(name = "userDao-zj")//相当于@Autowired@Qualifier
    private UserDao userDao;

    @Value("张三")
    private String name;
    @Value("${jdbc.driver}")
    private String driver;

    @Override
    public void sayHello() {
        userDao.save();
        System.out.println("sayHello="+name);
        System.out.println(driver);
    }
}
